﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using GrewalCRM.Entities.Common;
using GrewalCRM.Entities;
using GrewalCRM.DAL;


namespace GrewalCRM.BLL
{
  public class SMSFailure_BLL : BaseBLLGrewalCRM
  {
      public SMSFailure_BLL()
    {
      baseDAL = new SMSFailure_DAL();
    }

    #region Public Methods
    public List<SMSFailure> GetAllFailedSMS()
    {
      List<BaseEntitiesGrewalCRM> baseEnteties = this.GetAll();
      List<SMSFailure> failedSMSs = new List<SMSFailure>();

      if (baseEnteties != null && baseEnteties.Count > 0)
      {
        foreach (BaseEntitiesGrewalCRM baseEntity in baseEnteties)
        {
            failedSMSs.Add(baseEntity as SMSFailure);
        }
      }

      return failedSMSs;
    }   
    
    public int Save(SMSFailure Entity)
    {
      int result = 0;
      EntityState state = EntityState.Nutral;

      if (Entity.ID == 0)
        state = EntityState.New;
      else if (Entity.IsMarkedDeleted)
        state = EntityState.Deleted;
      else if (Entity.IsChanged)
        state = EntityState.Changed;

      switch (state)
      {
        case EntityState.New:
          result = AddNew(Entity);
          break;
        case EntityState.Deleted:
          result = Delete(Entity);
          break;
        case EntityState.Changed:
          result = Update(Entity);
          break;
        default:
          result = 0;
          break;

      }

      return result;
    }

    protected override int AddNew(BaseEntitiesGrewalCRM Entity)
    {
      return baseDAL.AddNew(Entity);
    }

    protected override int Update(BaseEntitiesGrewalCRM Entity)
    {
      return baseDAL.Update(Entity);
    }

    protected override int Delete(BaseEntitiesGrewalCRM Entity)
    {
      return baseDAL.Delete(Entity);
    }

    protected override List<BaseEntitiesGrewalCRM> GetAll()
    {
      return baseDAL.GetAll();
    }

    protected override BaseEntitiesGrewalCRM GetByID(int ID)
    {
      throw new NotImplementedException();
    }

    protected override void FillEntity(BaseEntitiesGrewalCRM Entity)
    {
      throw new NotImplementedException();
    } 
    #endregion
  }
}
